package web;

//import java.net.MalformedURLException;
//import java.net.URL;
//import java.sql.Struct;
import java.io.*;
import java.util.Collection;

import ui.MainWindow;
/*
import java.util.List;
import java.util.Vector;

import org.apache.xmlrpc.XmlRpcConfigImpl;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.XmlRpcRequest;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
import org.apache.xmlrpc.client.XmlRpcCommonsTransportFactory;
import org.apache.xmlrpc.common.XmlRpcHttpRequestConfig;
import org.apache.commons.httpclient.*;
*/
import de.umass.lastfm.Track;


public class WebInitializer {

	public String api_key = "bf9855679f24f8f11002e87364f6e85f";
	//public String user = "joanofarctan";
	//public String rootURL = "http://ws.audioscrobbler.com/2.0/?";
	//public String methodName = "user.gettoptags";
	
	public int numResults = 10;
	
	public WebInitializer()
	{
		InputStreamReader input = new InputStreamReader(System.in);
		BufferedReader cin = new BufferedReader(input);
		
		System.out.println("Enter the name of a song: ");
		String track;
		try
		{
			track = cin.readLine();
		}
		catch(IOException e)
		{
			String defaultTrack = "Don't Stop Me Now";
			System.err.println("Error. Using default title: \"" + defaultTrack + "\"");
			track = defaultTrack;
		}
		
		System.out.println("Enter an associated artist (if possible): ");
		String artist;
		try
		{
			artist = cin.readLine();
		}
		catch(IOException e)
		{
			artist = null;
		}
		
		System.out.println("Getting data");
		Collection<Track> t;
		
		if(artist == null || artist.length() == 0)
		{
			System.out.println("No artist");
			t = Track.search(track, api_key);
		}
		else
			t = Track.search(artist, track, numResults, api_key);
		
		for  (Track t_ : t)
		{
			System.out.println(t_.toString());
		}
		
		//Testing Main Window
		MainWindow mw = new MainWindow();
		mw.setVisible(true);
	}	
}
